﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KendoMvcUI.Enums;
using KendoMvcUI.Common;

namespace KendoMvcUI.UI
{
    public class DataSourceSettings
    {
        public DataSourceSettings()
        {
            Transport = new TransportSettings();
        }
        /// <summary>
        /// 数组：如：['123','345','data']
        /// </summary>
        public string Data { get; set; }

        public TransportSettings Transport { get; set; }
        public override string ToString()
        {
            var dataSource = "";
            if (!Data.IsNullOrWhiteSpace())
                dataSource += "data:{0},".Formator(Data);
            if (Transport != null&&!Transport.ToString().IsNullOrWhiteSpace())
                dataSource +=  Transport.ToString() + ",";

            return "dataSource:{"+dataSource.TrimEnd(',')+"}";
        }
            
    }
    public class TransportSettings
    {
        public TransportSettings()
        {
            Read = new ReadSettings();
        }
        public ReadSettings Read { get; set; }

        public override string ToString()
        {
            var transport = "";
            if (Read != null&&!Read.ToString().IsNullOrWhiteSpace())
            {
                transport += Read.ToString();
                return "transport:{" + transport.TrimEnd(',') + "}";
            }

            return "";
        }
    }
    public class ReadSettings
    {
        public ReadSettings()
        {
            DataType = KendoMvcUI.Enums.DataType.json;
        }
        public string Url { get; set; }
        public DataType DataType { get; set; }

        public override string ToString()
        {
            if (!Url.IsNullOrWhiteSpace())
            {
                string read = "dataType:'{0}',".Formator(this.DataType.ToString());
                read += "url:'{0}',".Formator(Url);
                return "read:{"+read.TrimEnd(',')+"}";
            }

            return "";
        }
    }
}
